<template>
  <div class="padding-across-10 main">
      <headerOpreate style="padding-bottom: 3px;float: left;width: 100%;padding-top: 5px" :opreate-datas="opreateDatas" v-on:executeAction="executeAction"></headerOpreate>
      <el-table border style="width: 100%;" @selection-change="handleSelectionChange" :data="tableData">
        <el-table-column label="标题" align="center" prop="Title"></el-table-column>
        <el-table-column label="内容" align="center" prop="Content" width="400px">
          <template slot-scope="scope">
            <span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">{{scope.row.Content}}</span>
          </template>
        </el-table-column>
        <el-table-column label="发布时间" align="center" prop="CreateTime"></el-table-column>
        <el-table-column :label="$t('message.operation')" align="center" width="100px">
          <template slot-scope="scope">
            <el-button size="small" type="primary" @click="editText(scope.row)"><i class="el-icon el-icon-information el-icon--left"></i>查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="text-align:right;margin-bottom:60px;padding-top: 2px;padding-bottom: 5px">
        <el-pagination
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          :current-page="currentPage"
          :page-size="pageSize"
          :page-sizes="[10,20,30,40,50]"
          layout="total, prev, pager, next, jumper"
          :total="totalSize">
        </el-pagination>
      </div>
      <!-- 编辑广告 -->
    <el-dialog title="通知公告" v-model="editAdDialog" :class="[dialog-small-width]">
      <el-form id="form" ref="createForm" :model="editForm" :rules="createRules" label-width="80px">
        <el-form-item label="标题" prop="title">
          <el-input disabled placeholder="请输入标题" v-model="editForm.title" required></el-input>
        </el-form-item>
        <el-form-item label="内容" prop="text">
          <el-input disabled type="textarea" :rows="5" placeholder="请输入内容" v-model="editForm.text" required></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editAdDialog = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import headerNave from '../../../components/headerNave'
  import headerOpreate from '../../../components/headerOpreate'
  import {GloabFun,HttpServer}from '../../../assets/js/common.js'
  export default {
    components:{
      headerNave,
      headerOpreate
    },
    data() {
      return {
        editAdDialog:false,
        editForm:{
          title:'',
          text:'',
        },
        tableData: [],
        multipleSelection:[],
        currentPage:1,
        pageSize:10,
        totalSize:0,
        opreateDatas:[
          {
            show: true,
            size:"small",
            type:'primary',
            icon:'el-icon-eleg-icon_refresh el-icon--left',
            name:'刷新',
            action:'reloadDatas'
          }
        ]
      }
    },
    props:{
        subArgs:{
            type: Object,
            default:function(){
              return {};
            }
        }
    },
    methods:{
      executeAction(action){
        if(action){
          this[action]();
        }
      },
      handleCurrentChange(val) {
        this.currentPage=val;
        this.getDatas();
      },
      handleSizeChange(val){
        this.pageSize = val;
        this.getDatas();
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      formateSelection(){
        var result = [],array = this.multipleSelection;
        for(var i = 0 ; i < array.length ; i ++){
          result.push(array[i].NoticeId);
        }
        return result;
      },
      //去掉时间中的T
      formateData(array){
         for(var i=0;i<array.length;i++){
          var index1=array[i].CreateTime.indexOf("T");
          array[i].CreateTime=array[i].CreateTime.substring(0,index1)+" "+array[i].CreateTime.substring(index1+1,index1+9);
         }
      },
      editText(row){
        this.editAdDialog = true;
        this.editForm = {
          title:row.Title,
          text:row.Content
        }
      },
      //刷新
      reloadDatas(){
        HttpServer.httpGet.call(this,'/Api/Notice/Info?page='+this.currentPage+'&size='+this.pageSize+'&examine=true',function(response) {
          },function(response){
            if(response.data.code === 0){
              this.formateData(response.data.info);
              this.tableData = response.data.info;
              this.totalSize = response.data.totalcount;
              this.$message({
                type:'success',
                message:this.$t('message.refreshSuccess')
              });
            }else{
              this.$message.error(response.data.msg);
            }
        });       
      },
      getDatas(){
        var isExamine = this.status ? true : false;
        HttpServer.httpGet.call(this,'/Api/Notice/Info?page='+this.currentPage+'&size='+this.pageSize+'&examine=true',function(response) {
          },function(response){
          	console.log(response)
            if(response.data.code === 0){
              this.formateData(response.data.info);
              this.tableData = response.data.info;
              this.totalSize = response.data.totalcount;
            }else{
              this.$message.error(response.data.msg);
            }
        });      
      },
    },
    created(){
      	this.getDatas();
    }
  }
</script>
<style scoped lang="less">
  .main{
    background-color: #fff;
    border-radius: 10px;
  }
  .name{
      color:#20a0ff;
   }
  .edit-mission{
    padding-top: 50px;
    .el-dialog__header{
      background-color: #000;
    }
    .el-dialog__body{
       position: relative;
     }
    .clearfloat{
       height:100px;
      max-height:150px;
     }
  }
</style>